<?php
session_start();
//error_reporting(E_STRICT | E_ALL);

// Provide AdWords login information.
//$email = 'info@ua-solutions.com';
//$password = 'uasolutions';
if(isset($_POST['task']) && $_POST['task']=='login') {
	$email = $_POST['email'];
	$password = $_POST['pwd'];	
	$params = array(
		'Email' => $email,
		'Passwd' => $password,
		'accountType' => 'GOOGLE',
		'service' => 'adwords',
		'source' => 'AdWords API PHP Code Example');
	
	$url = 'https://www.google.com/accounts/ClientLogin';
	
	// Make request
	$ch = curl_init($url);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
	$response = curl_exec($ch);
	curl_close($ch);
	
	// Parse response.
	$lines = explode("\n", $response);
	foreach ($lines as $line) {
	  $parts = explode('=', $line, 2);
	  if ($parts[0] == 'Auth') {
		$authToken = $parts[1];
	  }
	  if ($parts[0] == 'Error') {
		$error = $parts[1];
	  }
	}
	
	// Display results.
	if (isset($authToken)) {
	  print 'Auth token: ' . $authToken . "\n";
	  $_SESSION['email'] = $_POST['email'];
	  $_SESSION['authToken'] = $authToken;
	  $_SESSION['pwd'] = $_POST['pwd'];
	  echo "<script type=\"text/javascript\">window.location='http://dmarketeer.com/aw_api_php_webapp_1.2.0/ManageCampaign.php';</script>";
	} else if (isset($error)) {
		echo "<script type=\"text/javascript\">alert('Username and password do not match or you do not have an account yet.');</script>";
	  //print 'Error: ' . $error . "\n";
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html slick-uniqueid="3" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" dir="ltr" lang="en-gb"><!-- Footer --><head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <meta name="generator" content="Humming! - Shopping cart">
  <title>Hummings - Administration</title>
  <script src="index_files/global.js" type="text/javascript"></script>
  <script src="index_files/jquery.js" type="text/javascript"></script>
  <script src="index_files/mootools-core.js" type="text/javascript"></script>
  <script src="index_files/core.js" type="text/javascript"></script>
  <script src="index_files/mootools-more.js" type="text/javascript"></script>
<!-- Load system style CSS -->
<link rel="stylesheet" href="index_files/system.css" type="text/css">

<!-- Load Template CSS -->
<link href="index_files/template.css" rel="stylesheet" type="text/css">

<!-- Load additional CSS styles for colors -->
<link href="index_files/colour_standard.css" rel="stylesheet" type="text/css">

<!-- Load additional CSS styles for rtl sites -->

<!-- Load specific language related css -->

<!-- Load additional CSS styles for bold Text -->

<!-- Load additional CSS styles for Internet Explorer -->
<!--[if IE 8]>
	<link href="insite/templates/hathor/css/ie8.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if IE 7]>
	<link href="insite/templates/hathor/css/ie7.css" rel="stylesheet" type="text/css" />
<![endif]-->
<!--[if lte IE 6]>
	<link href="insite/templates/hathor/css/ie6.css" rel="stylesheet" type="text/css" />
<![endif]-->

<!-- Load Template JavaScript -->
<script type="text/javascript" src="index_files/template.js"></script>
<link href="index_files/style.css" rel="stylesheet" type="text/css">
<link href="index_files/forms.css" rel="stylesheet" type="text/css">
<link href="index_files/tooltip.htm" rel="stylesheet" type="text/css">


</head>
<body id="login-page">
	<div id="containerwrap">

		<!-- Header Logo -->
		<div id="header">
			<h1 class="title">Administration</h1>
		</div><!-- end header -->

		<!-- Content Area -->
		<div id="content">

			<!-- Beginning of Actual Content -->
      <div id="element-box" class="login">
  <div class="pagetitle">
    <h2>API Login</h2>
  </div>
  
  <!-- System Messages -->
  
  <div id="system-message-container">
    
  </div>
  <div class="login-inst">
    <p>Use a valid username and password to gain access to the administrator backend.</p>
    <div id="lock"></div>
    <a href="#">Go to site home page.</a> </div>
  
  <!-- Login Component -->
  <div class="login-box">
    <form action="http://dmarketeer.com/aw_api_php_webapp_1.2.0/login.php" method="post" id="form-login">
      <fieldset class="loginform">
        <label id="mod-login-username-lbl" for="mod-login-username">User Name</label>
        <input name="email" id="mod-login-username" type="text" class="inputbox" size="15" />
        <label id="mod-login-password-lbl" for="mod-login-password">Password</label>
        <input name="pwd" id="mod-login-password" type="password" class="inputbox" size="15" />
        
        <!--<label id="mod-login-language-lbl" for="lang">Language</label>
				<select id="lang" name="lang"  class="inputbox">
	<option value="" selected="selected">Default</option>
	<option value="en-GB">English (United Kingdom)</option>
</select>-->
        
        <div class="button-holder">
          <div class="button1">
            <div class="next"> <a href="#" onClick="document.getElementById('form-login').submit();"> Log in</a> </div>
          </div>
        </div>
        <div class="clr"></div>
        <input type="submit" class="hidebtn" value="Log in" />
        <input type="hidden" name="task" value="login" />
      </fieldset>
    </form>
  </div>
  <div class="clr"></div>
</div>
      
			<!-- end element-box -->

		<noscript>
			Warning! JavaScript must be enabled for proper operation of the Administrator backend.		</noscript>

		</div><!-- end content -->
		<div class="clr"></div>
	</div><!-- end of containerwrap -->

	<!-- Footer -->
	<div id="footer">
		<p class="copyright">http://dmarketeer.com/
				</p>
	</div>
</body></html>
